package com.smile.http;

import com.smile.data.dto.ProductItemQueryDto
import com.smile.data.entity.ProductItemEntity
import com.smile.response.ResultEmpty
import com.smile.response.ResultPage
import com.smile.service.ProductItemService
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = ["商品管理"])
@RestController
@RequestMapping("/products/items")
class ProductItemController {
    @Autowired
    lateinit var service: ProductItemService

    @GetMapping
    @ApiOperation("分页查询")
    fun query(dto: ProductItemQueryDto): ResultPage<ProductItemEntity> {
        return service.query(dto);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    fun queryById(@PathVariable id: String) : ProductItemEntity{
       return service.queryById(id);
    }

    @PostMapping
    @ApiOperation("创建商品")
    fun create(@RequestBody dto: ProductItemEntity) : ResultEmpty{
        return service.create(dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改商品")
    fun update(@PathVariable id: String, @RequestBody dto: ProductItemEntity) : ResultEmpty{
        return service.update(id, dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除商品")
    fun remove(@PathVariable id: String) : ResultEmpty{
        return service.remove(id);
    }
}
